
"""
    使用消息队列进行进程间的通信
"""
import time
import multiprocessing


def write_queue(queue1):
    for i in range(10):
        if queue1.full():
            print("队列已满")
            break

        print("向队列中放入%d" % i)
        queue1.put(i)
        time.sleep(1)


def read_queue(queue1):
    for i in range(10):
        if queue1.empty():
            print("队列为空")
            break

        value = queue1.get()
        print("成功从队列中取出%d" % value)


if __name__ == '__main__':
    queue1 = multiprocessing.Queue(5)

    process_write = multiprocessing.Process(target=write_queue, args=(queue1, ))
    process_read = multiprocessing.Process(target=read_queue, args=(queue1, ))

    process_write.start()

    process_write.join()

    process_read.start()
